<?php

namespace App\Listeners;

use App\Events\ExampleEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Log;

class ExampleSubscribe implements ShouldQueue
{
    public $queue = 'ExampleSubscribe{queue}';

    /**
     * 为事件订阅者注册监听器
     *
     * @param Dispatcher $events
     */
    public function subscribe(Dispatcher $events)
    {
        $events->listen(
            'App\Events\ExampleEvent',
            'App\Listeners\ExampleSubscribe@handleUserExample'
        );
        $events->listen(
            'App\Events\ExampleEvent',
            'App\Listeners\ExampleSubscribe@handleUserExample2'
        );
    }

    public function handleUserExample()
    {
        Log::info('handleUserExample');
    }

    public function handleUserExample2()
    {
        Log::info('handleUserExample2');
    }

    /**
     * @param ExampleEvent $event
     * @param $exception
     * @return void
     */
    public function failed(ExampleEvent $event, $exception)
    {
        Log::info('this is failed listeners queue of exampleListener '.json_encode($event->data,JSON_UNESCAPED_UNICODE));
    }

    //处理超过最大时间 --timeout或retry_after
//    public function retryUntil()
//    {
//        return false;
//    }
}